<template>
  <el-config-provider :locale="locale" :size="assemblySize" :button="buttonConfig">
    <router-view />
  </el-config-provider>
</template>

<script setup lang="ts">
import {globalStore} from "@/stores/modules/global";
import {useTheme} from "@/hooks/useTheme.ts";
import {useI18n} from "vue-i18n";
import {computed, onMounted, reactive} from "vue";
import {getBrowserLang} from "@/helper";
import {LanguageType} from "@/interface";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import en from "element-plus/es/locale/lang/en";
const globalState = globalStore();

// init theme
const { initTheme } = useTheme();
initTheme();

// init language
const i18n = useI18n();
onMounted(() => {
  const language = globalState.language ?? getBrowserLang();
  i18n.locale.value = language;
  globalState.setGlobalState("language", language as LanguageType);
});

// element language
const locale = computed(() => {
  if (globalState.language == "zh") return zhCn;
  if (globalState.language == "en") return en;
  return getBrowserLang() == "zh" ? zhCn : en;
});

// element assemblySize
const assemblySize = computed(() => globalState.assemblySize);

// element button config
const buttonConfig = reactive({ autoInsertSpace: false });
</script>

<style lang="scss" scoped>

</style>
